package com.ktjy.controller;

import com.ktjy.entity.User;
import jakarta.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {
    Logger logger = LoggerFactory.getLogger(UserController.class);

    @RequestMapping("/list")
    public String list(HttpServletRequest request) {
        String name=request.getParameter("name");
        String age=request.getParameter("age");
        logger.info("name:"+name+",age:"+age);
        return null;
    }
    @RequestMapping("/view")
    public String view(@RequestParam("id")Integer id) {
        logger.info("id:"+id);
        return null;
    }
    @RequestMapping("/add")
    public String add() {
        return "add";
    }
    @RequestMapping("/save")
    public String save(User user) {
        logger.info("user:"+user);
        return null;
    }
    @RequestMapping("/list1")
    public String list1(HttpServletRequest request,Model model) {
        String name=request.getParameter("name");
        String age=request.getParameter("age");
        logger.info("name:"+name+",age:"+age);

        List<User> list=new ArrayList<>();
        list.add(new User(1,"张三",18));
        list.add(new User(2,"李四",19));
        list.add(new User(3,"王五",20));

        model.addAttribute("list",list);
        return "list";
    }
}
